package org.example.finalsecurities.controller;

import org.example.finalsecurities.entity.Result;
import org.example.finalsecurities.entity.StockIndex;
import org.example.finalsecurities.service.StockIndexService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 股票指数controller
 * 功能：
 * 1. 查询所有股票指数
 * 2. 根据股票指数代码查询股票指数
 * 3. 插入股票指数
 * 4. 通过股票指数代码更新股票指数
 *
 * @author : [CaiJianbin]
 * @version : [v1.0]
 */
@RestController
@RequestMapping("/api/stock")
public class StockIndexController {

    @Autowired
    private StockIndexService stockIndexService;

    @GetMapping("/all")
    public Result getAllStockIndices() {
        return Result.success(stockIndexService.getAllStockIndices());
    }

    @GetMapping("/fetch")
    public void fetchAndUpdateStockIndices() {

        stockIndexService.fetchAndUpdateChinaIndexes();
    }

    @GetMapping("/{code}")
    public Result getStockIndexByCode(@PathVariable String code) {
        return Result.success(stockIndexService.getStockIndexByCode(code));

    }
}